package largestNumber;

import java.util.Arrays;
import java.util.Comparator;

public class Solution {
    public String largestNumber(int[] nums) {
        String ans=new String();
        String[] numString=new String[nums.length];
        for (int i=0;i<nums.length;i++)
			numString[i]=Integer.toString(nums[i]);

        
        Arrays.sort(numString, new cmp());
        for (int i=0;i<nums.length;i++){
        	ans=ans+numString[i];
        }
        if (ans.charAt(0)=='0') return "0";
        return ans;
    }
    class cmp implements Comparator<String>{	
		public int compare(String o1, String o2) {
			Long a=Long.parseLong(o1+o2);
			Long b=Long.parseLong(o2+o1);
			return (int) (b-a);
		}
    	
    }
    public static void main(String args[]){
    	Solution so=new Solution();
    	int[] nums=new int[]{999999998,999999997,999999999};
    	System.out.println(so.largestNumber(nums));
    }
    /* 蜜汁排序题。。思路进了死胡同。。纠结于完全没必要的坑里
     * 179 LargestNumber
     * */
    
}